<?
	require_once('../inc/orderitemsfunc.php');
	$results = GetOIs();	
	
	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
	$row = $_REQUEST;
	if($action==='delete'){
		$id = $_GET['id'];
		$rts = DeleteOI($row, $_REQUEST['id']);
		if($rts === true){
			header("Location: index.php");
			die();
		}
		else{
			echo "Couldn't delete order items.";
		}
	}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta charset="utf-8" />
		<title>Order Items Page</title>
		<script type='text/javascript'>	    
		    function delete_user(id){
		        var answer = confirm('Are you sure?');        
		        if (answer){
		        	window.location = 'index.php?action=delete&id=' + id;
		        	return false;
	        	}
	        }
		</script>
		<style type="text/css">
			.error {color:red;}
		</style>
	</head>

	<body>
		<br />
            <table border="1">
                <tr>
                	<th>Order Items id</th>
                	<th>Order id</th>
                	<th>Products id</th>
                	<th>Created at</th>
                	<th>Updated at</th>
                	<th>Quantity</th>
                    <th>Quantity Price</th>
                    <th>Actions</th>
                </tr>
                <? while($rs = $results->fetch_assoc()):?>
                    <tr>
                    	<td><?=$rs['orderitems_id']?></td>
                    	<td><?=$rs['order_id']?></td>
                    	<td><?=$rs['products_id']?></td>
                    	<td><?=$rs['created_at']?></td>
                    	<td><?=$rs['updated_at']?></td>
                    	<td><?=$rs['quantity']?></td>
                        <td><?=$rs['quantity_price']?></td>
                        <td>
                            <a href="edit.php?id=<?=$rs['orderitems_id']?>">Edit</a>
                            <a href="" onclick="return delete_user(<?=$rs['orderitems_id']?>)">Delete</a>
                        </td>
                     </tr>
                <? endwhile; ?>
           </table>
           <a href="create.php">Create a new order item.</a>
           <br />
           <a href="../index.php">To all pages.</a>
       </div>
    </div>                
	</body>
</html>